﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;

namespace FormEditor.Handler
{
    /// <summary>
    /// UsersHandler 的摘要说明
    /// </summary>
    public class UsersHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string actiontype = context.Request.QueryString["actiontype"];
            switch (actiontype)
            {
                case "getusers":
                    context.Response.Write(JsonConvert.SerializeObject(GetUser()));
                    break;
                case "getnations":
                    context.Response.Write(JsonConvert.SerializeObject(GetNations()));
                    break;
                default:
                    break;
            }
        }
        private List<Nationality> GetNations()
        {
            List<Nationality> Nation = new List<Nationality>();
            Nationality n1 = new Nationality() { Code = 1, Name = "汉族" };
            Nationality n2 = new Nationality() { Code = 2, Name = "回族" };

            Nation.Add(n1);
            Nation.Add(n2);

            return Nation;
        }
        private Users GetUser()
        {
            Users users = new Users()
            {
                ID = 1,
                Email = "jackandmary@qq.com",
                Name = "jack",
                Pass = "123",
                Sex = true,//true表示选择男，2表示选择女
                IsUse = true,
                NationType = 2,
                QQ = "123455",
                Address = "广州天河区",
                Phone = "1350000000"
            };
            return users;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}